import pymysql

HOST = '10.10.200.34'
PORT = 3306
USER = 'bmwms_test'
PASSWD = 'J3tATjN3B8CwA8GP'
DB = 'bmwms_test'
CHARSET = 'utf8'
def getAllTableName() -> tuple:
    """
    获取所有表名
    :return:
    """
    connection = pymysql.connect(host=HOST,
                                 port=PORT,
                                 user=USER,
                                 passwd=PASSWD,
                                 db=DB,
                                 charset=CHARSET)
    cursor = connection.cursor()

    cursor.execute(
        "select table_name from information_schema.tables where table_schema='bmwms_test'  and( TABLE_NAME like 'wms%')")
    data = cursor.fetchall()
    cursor.close()
    connection.close()
    return data


def getAllAttrByTableName(tableName: str) -> tuple:
    """
    获取一个表格的所有字段
    :return:
    """
    """
    获取所有表名
    :return:
    """
    connection = pymysql.connect(host=HOST,
                                 port=PORT,
                                 user=USER,
                                 passwd=PASSWD,
                                 db=DB,
                                 charset=CHARSET)
    cursor = connection.cursor()

    cursor.execute("select COLUMN_NAME from information_schema.COLUMNS where table_name = '" + str(tableName) + "';")
    data = cursor.fetchall()
    cursor.close()
    connection.close()
    return data


def getAllAttrTypeAndSizeByTableNameAndAttrName(tableName: str, attrName: str) -> tuple:
    """
    获取一个表格的所有字段
    :return:
    """
    """
    获取所有表名
    :return:
    """
    connection = pymysql.connect(host=HOST,
                                 port=PORT,
                                 user=USER,
                                 passwd=PASSWD,
                                 db=DB,
                                 charset=CHARSET)
    cursor = connection.cursor()

    cursor.execute(
        "SELECT  COLUMN_TYPE  FROM information_schema.`COLUMNS` where TABLE_SCHEMA like 'bmwms_test' and TABLE_NAME='" + str(
            tableName) + "' and COLUMN_NAME='" + attrName + "';")
    data = cursor.fetchall()
    cursor.close()
    connection.close()
    return data
